
These are 8 bit samples often used with the first Amiga trackers of the late
80s and early 90s, like Ultimate Soundtracker. In original and updated formats.

Following the info found in [this other archive][other], I tried to accurately
convert the original files to modern & self documenting formats (.wav or
.aiff), so they can easily be used in modern DAWs or modern trackers, like
Renoise. Try to disable interpolation, and adding a 2 poles low pass filter at
around 7 kHz for an old school experience.

[other]: https://archive.org/details/AmigaSTXX

## Disclaimer

The original files were not collected by me. They are on Aminet:

- <http://aminet.net/mods/inst>.

I am not an Amiga or sound files expert, just an enthousiast and curious
developer. As such, I might have done a few errors. I would appreciate if more
knowledgeable people took the time to check my work, and if you happen to find
an error and have a way to fix it, please do so.

To gather some data about the original files, I explored mostly the `ST-01` and
`ST-02` directories for reference, then I did a few stats on all the
directories. But I didn't check the 10500+ original files individually.

## Notes on the original files

First, using hexadecimal file viewers like GNU od and xxd, and D3.js to display
the data, I found that interpreting files as 8 bit signed ints shows nice
curves for some files.

I also found that a few of them (only 1 in the `ST-01` directory) started by
the 'FORM' word, followed by '8SVX' a few bytes later. This indicates an IFF
header for sound data.

After a few more research (see reference links below), I found out that 8SVX
IFF files contain info aboute the bit precision, and more importantly the
sample rate of the original file.

A few stats: There are 4662 files with an IFF header in the original
collection, from 10500+ files total. So around 44 % of the originals are IFF
files, and 56 % are raw PCM data with no header.

Command to count files with an IFF header in the original files:

```
$ find . -type f -not -name '*.aiff' -not -name '*.wav' -print0 | xargs -0 grep -l '^FORM' | wc -l
```

## Notes on the conversion

### Converting raw files

For the raw files, I wrote a Python Script that can:
- read a raw file
- generate an AIFF header with values corresponding to the raw data,
- create an AIFF file, by pasting the header to the raw data.

This means that if you remove the generated header of the AIFF files, you
should find exactly the original raw file.

Here is the command I used, from the root of the archive:

```
$ find . -type f -not -name '*.aiff' -not -name '*.wav' -print0 | xargs -0 grep -ZL '^FORM' | xargs -0 -n1 -I {} python3 convert_to_aiff.py {}
```

The script is at the root of the archive. I would be grateful if someone would
check it and review it. It works only for raw 8 bit signed mono data.

Note: since I use the `-Z` grep option that is not supported by macOs's old
version of grep, I had to use ggrep, which points to GNU grep on my mac. You
can install most GNU replacements for macOs with Homebrew. If you're on a real
Linux, you're fine, your grep is probably a recent version of GNU grep.

### Converting IFF files

Since IFF files have many optional chunks, I wanted to avoid writing a parser
for 8SVX header to extract the sample rate and other data about the IFF files.
So I used [SoX][sox] (Sound eXchange) to read and convert all files starting by
a 'FORM' magic number header. SoX had no problem parsing them and converting
them to `.wav`.

IFF files can contain basic looping points, by spliting the data into a first
part (one shot) and a repeating part. The whole data should be present in the
.wav files, but if the original files contained looping points, I was not able
to preserve them.

Here is the command I used, from the root of the archive:

```
$ find . -type f -not -name '*.aiff' -not -name '*.wav' -print0 | xargs -0 grep -Zl '^FORM' | xargs -0 -n1 -I {} sox {} {}.wav
```

[sox]: http://sox.sourceforge.net/

## Notes on the sample rates

`.wav` files where converted from 8SVX IFF files using SoX. These files had
information about their sample rate, and should be tuned as well as their
original sample was.

Some stats : on the 4662 IFF files, 1783 are in 16726 Hz, and 2401 are in 8363
Hz. That would be 90 % of the IFF files.

`.aiff` files where generated from raw 8 bit signed PCM data, without header
and without info about their original sample rate. Since 90 % of the IFF files
had a sample rate of either 16726 Hz or 8363 Hz, I chose to write 16726 HZ in
the AIFF header for the `.aiff` files. If the sample plays too fast in your
DAW, try to play it an octave lower, it should sound ok in most cases.

Command to gather stats on the IFF files sample rates:

```
find . -type f -not -name '*.aiff' -not -name '*.wav' -print0 | xargs -0 ggrep -Zl '^FORM' | xargs -0n1 xxd -p -s32 -l2 | sort | uniq -c
```

Note: counts are decimal numbers, sample rates are hexadecimal numbers.

## References I used

Original files:

- <https://archive.org/details/AmigaSTXX>
- <http://aminet.net/mods/inst>.

About ST-01 samples:

- <http://www.polynominal.com/Commodore-Amiga/soundtracker-st01-original-synthesizer-source.html>

About IFF and 8SVX:

- <https://wiki.amigaos.net/wiki/8SVX_IFF_8-Bit_Sampled_Voice>
- <http://sox.sourceforge.net/AudioFormats-11.html#ss11.3>
- <https://en.wikipedia.org/wiki/8SVX>

About AIFF:

- <http://paulbourke.net/dataformats/audio/>
- <https://github.com/audacity/audacity/blob/fa00dd0/lib-src/libsndfile/src/aiff.c>
- <https://en.wikipedia.org/wiki/Audio_Interchange_File_Format>

I did not explore enough, but Python can do a few things with IFF or AIFF
data and audio files in general:
- <https://docs.python.org/3/library/mm.html>
- <https://docs.python.org/3/library/chunk.html>
- <https://docs.python.org/3/library/sndhdr.html>
